{% from 'macros.html' import follow_area with context %}
{% from 'bootstrap/nav.html' import render_nav_item %}


<div class="row">
    <div class="col-md-3">
        <a href="{% if current_user == user %}{{ url_for('.change_avatar') }}{% else %}#{% endif %}"
           title="Change avatar">
            <img class="img-fluid rounded" src="{{ url_for('main.get_avatar', filename=user.avatar_l) }}">
        </a>
    </div>
    <div class="col-md-9">
        <h1>{{ user.name }}
            <small class="text-muted">{{ user.username }}</small>
        </h1>
        {% if user.bio %}<p>{{ user.bio }}</p>{% endif %}
        <p>
            {% if user.website %}
                <span class="oi oi-link-intact"></span>
                <a href="{{ user.website }}" target="_blank">{{ user.website|truncate(30) }}</a>&nbsp;&nbsp;
            {% endif %}
            {% if user.location %}
                <span class="oi oi-map-marker"></span>
                <a href="https://www.google.com/maps?q={{ user.location }}"
                   target="_blank">{{ user.location|truncate(30) }}</a>&nbsp;&nbsp;
            {% endif %}
            <span class="oi oi-calendar"></span>
            Joined {{ moment(user.member_since).format('LL') }}
        </p>
        <div>
            {% if current_user != user %}
                {% if current_user.can('MODERATE') %}
                    {% if user.locked %}
                        <form class="inline" action="{{ url_for('admin.unlock_user', user_id=user.id) }}" method="post">
                            <input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
                            <input type="submit" class="btn btn-secondary btn-sm" value="Unlock">
                        </form>
                    {% else %}
                        <form class="inline" action="{{ url_for('admin.lock_user', user_id=user.id) }}" method="post">
                            <input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
                            <input type="submit" class="btn btn-warning btn-sm" value="Lock">
                        </form>
                    {% endif %}
                    {% if user.active %}
                        <form class="inline" action="{{ url_for('admin.block_user', user_id=user.id) }}" method="post">
                            <input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
                            <input type="submit" class="btn btn-warning btn-sm" value="Block">
                        </form>
                    {% else %}
                        <form class="inline" action="{{ url_for('admin.unblock_user', user_id=user.id) }}"
                              method="post">
                            <input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
                            <input type="submit" class="btn btn-secondary btn-sm" value="Unblock">
                        </form>
                    {% endif %}
                    <a class="btn btn-light btn-sm" href="mailto:{{ user.email }}">Email</a>
                {% endif %}

                {% if current_user.is_admin %}
                    <a class="btn btn-warning btn-sm" href="{{ url_for('admin.edit_profile_admin', user_id=user.id) }}">Edit
                        profile</a>
                {% endif %}
            {% endif %}
            <div class="float-right">
                {{ follow_area(user) }}
                {% if current_user.is_authenticated and user == current_user %}
                    <a class="btn btn-outline-primary btn-sm" href="{{ url_for('.edit_profile') }}">Edit profile</a>
                {% endif %}
            </div>
        </div>
    </div>
</div>
<div class="user-nav">
    <ul class="nav nav-tabs">
        {{ render_nav_item('user.index', 'Photo', user.photos|length, username=user.username) }}
        {{ render_nav_item('user.show_collections', 'Collections', user.collections|length, username=user.username) }}
        {{ render_nav_item('user.show_following', 'Following', user.following.count() - 1, username=user.username) }}
        {{ render_nav_item('user.show_followers', 'Follower', user.followers.count() - 1, username=user.username) }}
    </ul>
</div>
